<?php
	class Add_product extends Controller{
		 function Add_product(){
			 
			 parent::Controller();
			 $this->load->model('addproductmodel');
			 $this->load->database();
			 $this->load->helper('url');
			 $this->load->helper('form');
			 $this->load->library('image_lib');
			 }
		function index(){
				$this->load->view('admin_addproduct');
			
			}
			function getSort(){
					$data=$this->addproductmodel->getSort();
					//print_r($data);
					$getChild=$this->addproductmodel->getChildren($data,0,0);
					$data['child']=$getChild;
					//print_r($data);
				$this->load->view('admin_addproduct',$data);
					
				}
			function getSortList(){
					
					$data=$this->addproductmodel->getSort();
					//print_r($data);
					$getChild=$this->addproductmodel->getChildren($data,0,0);
					$data['child']=$getChild;
					//print_r($data);
				$this->load->view('sort_list',$data);
				}
		
			
			function add(){
				//print_r($_POST);exit;
				//$data=$this->upload_file();
				//print_r($data);exit;
				$this->load->library('upload');
				$userfile_data = $_FILES['userfile'];
				$imgname_one = $this->upload->do_upload_ex("userfile",$userfile_data,false,"/uploads/goods/","/uploads/goods_thumb/",true); //单图片上传 缩略图生成
				//print_r($imgname_one);
				$_POST['picture']=$imgname_one[0];
				//print_r($_POST);
				$this->addproductmodel->insertProduct($_POST);
				
				echo "添加成功";
					echo anchor('add_product/getSort/','返回');
				}
			function image_form(){
					$this->load->view('upload_form');
				}
				function test_thumb_image(){
						$this->load->library('upload');
						$userfile_data = $_FILES['userfile'];
						$imgname_one = $this->upload->do_upload_ex("userfile",$userfile_data,false,"/uploads/news/","/uploads/news_thumb/",true); //单图片上传 缩略图生成
						print_r($imgname_one);exit;
						
						
					}
				
				
				function pagelist(){
					
						$page_num = '2';
						$data= $this->addproductmodel->page($page_num,$this->uri->segment(3));
						//print_r($data);exit;
						$data['query']=$data[1];
						//print_r($data['query']);exit;
						
						//foreach($data[1] as $values)
							//foreach($values as $rows)
						//{
							//print_r($values->content);
						//}
						
					
						
						 $this->load->library('pagination');
		$config['base_url'] = $this->config->item('base_url').'/index.php/add_product/pagelist/';
		$config['total_rows'] = '200';
		$config['per_page'] = $page_num; 
		$config['first_link'] = '首页';
		$this->pagination->initialize($config); 
		echo $this->pagination->create_links();
		
		$this->load->view('admin_listProduct',$data);
					}


		function upload_file(){
      
  	  $config['upload_path'] = './uploads/';
  	  $config['allowed_types'] = 'gif|jpg|png';
  	  $config['max_size'] = '1000';
      $config['max_width']  = '1024';
      $config['max_height']  = '768';
      $config['encrypt_name']  = true;
      $this->load->library('upload', $config);
     if( ! $this->upload->do_upload()){
   		$error = array('error' => $this->upload->display_errors());
   		return $error;
  	 }else{
   		$data = array('upload_data' => $this->upload->data());
		//print_r($data)
   		return  $data;
      }
   } 
		
		
		}

?>